package de.baumann.browser.fragments

import android.support.v7.widget.LinearLayoutManager
import android.view.View
import de.baumann.browser.R
import de.baumann.browser.adapter.LicenceOrderAdapter
import de.baumann.browser.api.net.vo.Order
import de.baumann.browser.base.BaseOdinFragment
import de.baumann.browser.iview.LicenceOrderView
import de.baumann.browser.present.LicenceOrderPresenter
import de.baumann.browser.utils.ViewUtil
import kotlinx.android.synthetic.main.fragment_licence_order.*

/**
 *@author:
 *@date:2019/7/4 19:53
 *@discription: Licence 订单
 */
class LicenceOrderFragment : BaseOdinFragment<LicenceOrderView, LicenceOrderPresenter>(), LicenceOrderView {

    private lateinit var licenceOrderAdapter: LicenceOrderAdapter

    companion object {
        val instance: LicenceOrderFragment by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            LicenceOrderFragment()
        }
    }

    override fun getLayout(): Int {
        return R.layout.fragment_licence_order
    }

    override fun initView(view: View) {
        rvLicenceOrder.layoutManager = LinearLayoutManager(context)
        licenceOrderAdapter = LicenceOrderAdapter(R.layout.recycler_item_licence_order)
        licenceOrderAdapter.emptyView = ViewUtil.emptyView(mContext)
        rvLicenceOrder.adapter = licenceOrderAdapter
    }

    override fun createPresenter(): LicenceOrderPresenter {
        return LicenceOrderPresenter()
    }

    override fun createView(): LicenceOrderView {
        return this
    }

    override fun initData() {
        getPresenter().getLicenceOrder()
    }

    override fun setLicenceOrders(orders: List<Order>?) {
        licenceOrderAdapter.setNewData(orders)
    }
}
